
; optimize the code for size
macro add arg1,arg2
 {
   if arg1 in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
      if arg2 eqtype 0
         if arg2 = 1
            inc arg1
         else
            add arg1,arg2
         end if
      else
         add arg1,arg2
      end if
   else
      if arg1 in <ax,bx,cx,dx,si,di,bp,sp>
         if arg2 eqtype 0
            if arg2 = 1
               inc arg1
            else
               add arg1,arg2
            end if
         else
            add arg1,arg2
         end if
      else
         add arg1,arg2
      end if
   end if
 }

macro sub arg1,arg2
 {
   if arg2 eqtype 0
      if arg2 = 1
         dec arg1
      else
         sub arg1,arg2
      end if
   else
      sub arg1,arg2
   end if
 }



macro cmp arg1,arg2
 {
   if arg1 in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
      if arg2 eqtype 0
         if arg2 = 0
            test arg1,arg1
         else
            cmp  arg1,arg2
         end if
      else
         cmp arg1,arg2
      end if
   else
      if arg1 in <ax,bx,cx,dx,si,di,bp,sp>
         if arg2 eqtype 0
            if arg2 = 0
               test arg1,arg1
            else
               cmp  arg1,arg2
            end if
         else
            cmp arg1,arg2
         end if
      else
         if arg1 in <al,bl,cl,dl,ah,bh,ch,dh>
            if arg2 eqtype 0
               if arg2 = 0
                  test arg1,arg1
               else
                  cmp  arg1,arg2
               end if       
            else
               cmp arg1,arg2
            end if
         else
            cmp arg1,arg2
         end if                         
      end if
   end if
 }

macro mov arg1,arg2
 {
   if arg1 in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
      if arg2 eqtype 0
         if arg2 = 0
            sub arg1,arg1
         else if arg2 = 1
            sub arg1,arg1
            inc arg1
         else if arg2 = -1
            or  arg1,-1
;         else if arg2 > -128 & arg2 < 128
;            push dword arg2
;            pop  arg1
         else
            mov  arg1,arg2
         end if
      else
         mov arg1,arg2
      end if
   else
      if arg1 in <ax,bx,cx,dx,si,di,bp,sp>
         if arg2 eqtype 0
            if arg2 = 0
               sub arg1,arg1
            else if arg2 = 1
               sub arg1,arg1
               inc arg1
            else if arg2 = -1
               or  arg1,-1
;            else if arg2 > -128 & arg2 < 128
;               push arg2
;               pop  arg1
            else
               mov  arg1,arg2
            end if
         else
            mov arg1,arg2
         end if
      else

         if arg1 in <ds,es,gs,fs,ss>
            if arg2 eqtype 0
               push arg2
               pop  arg1
            else if arg2 in <ds,es,gs,fs,ss,cs>
               push arg2
               pop  arg1            
            else 
               mov arg1,arg2
            end if
         else
            mov arg1,arg2
         end if                          

      end if                           
   end if
 }

macro StdIODelay  {   jmp     $+2      }

macro OldIoDelay  {   StdIODelay       }

macro IoDelay     {   out     0xEB,al  }

macro align value { rb (value-1) - ($ + value-1) mod value }

macro reset       {
        mov     al,0xFE
        out     0x64,al
                  }

;struc Exceptions
;        {
;     .DE        = 0x00   ; Div by 0
;     .DB        = 0x01   ; Debug
;     .NMI       = 0x02   ; Non maskable interrupt     
;     .BP        = 0x03   ; Break point 
;     .OF        = 0x04   ; Overflow
;     .BR        = 0x05   ; Bound range exceeded     
;     .UD        = 0x06   ; Illegal instruction
;     .NM        = 0x07   ; Processor extension not availabale
;     .DF        = 0x08   ; Double fault
;     .EF        = 0x09   ; Processor extension protection fault
;     .TS        = 0x0A   ; Invalid task state segment
;     .NP        = 0x0B   ; Segment not present
;     .SS        = 0x0C   ; Stack fault
;     .GP        = 0x0D   ; General protection fault
;     .PF        = 0x0E   ; Page fault
;     .MF        = 0x10   ; Coprocessor error     
;     .AC        = 0x11   ; Alignment error
;     .MC        = 0x12   ; Machine chech exception
;        }
;Exception Exceptions
